﻿Public Class DRUGINFORMANT
    Dim connect As CONDB = CONDB.NewConnection()
    'Dim connectlocal As conlocal = conlocal.NewConnection
    Dim PROVIDER_Check As New PROVIDERSCLASS

    Private Sub DRUGINFORMANT_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        SelectDatagridMASINFOR()

        DesignForm(Me)
        DesignGrid(masinforGrid)

        PROVIDER_Check.GETHOSEM(CInt(main.txtUserRequest.Text.Trim), Convert.ToString(Me.Tag))
    End Sub

    Private Sub SelectDatagridMASINFOR()
        Dim objSelectDataMASINFOR As New masinfor
        Dim MASINFOR As DataTable
        MASINFOR = connect.GetTable(objSelectDataMASINFOR.selectMasinfor_)
        masinforGrid.PrimaryGrid.DataSource = MASINFOR
    End Sub

    Private Sub masinforGrid_CellClick(sender As Object, e As DevComponents.DotNetBar.SuperGrid.GridCellClickEventArgs) Handles masinforGrid.CellClick
        Dim grid As DevComponents.DotNetBar.SuperGrid.GridRow
        grid = e.GridPanel.ActiveRow
        'f.TXT_CID.Text = grid.Cells.Item(2).Value
        INFIDTxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("รหัสผู้ให้ข้อมูล").Value()
        INFORMANTTxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ผู้ให้ข้อมูล").Value()

        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("สถานะการเปิดใช้งาน").Value() = True Then
            masinforStatusChk.Checked = True
        Else
            masinforStatusChk.Checked = False
        End If

        Dim objChkboxUpdate As New CLICKGRIDCHECKBOX
        objChkboxUpdate.clickChkboxUpdate("masinfor", CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("สถานะการเปิดใช้งาน").Value(), "STATUS", "INFID", INFIDTxt.Text)
    End Sub


    Private Sub addMasinfor_Click(sender As Object, e As EventArgs) Handles addMasinfor.Click
        If main.PROVIDERPOLICIES.checklogin_user_ = True Then
            If PROVIDER_Check.PADD_ = True Then
                If INFORMANTTxt.Text.ToString.Length > 0 Then
                    Dim objInsertData As New masinfor
                    objInsertData.INFORMANT_ = INFORMANTTxt.Text
                    objInsertData.STATUS_ = masinforStatusChk.Checked
                    objInsertData.insertMasinforData()

                    SelectDatagridMASINFOR()

                    INFIDTxt.Text = ""
                    INFORMANTTxt.Text = ""
                    masinforStatusChk.Checked = False
                Else
                    MsgBox("โปรดระบุข้อมูลให้ครบถ้วน")
                End If
            Else
                MsgBox(PROVIDER_Check.PADDMSG_)
            End If
        Else
            TOASTCLASS.gloadToastMSG(Me, main.PROVIDERPOLICIES.LOGINUSERMSG_)
            main.txtUserRequest.Focus()
        End If
    End Sub

    Private Sub editMasinfor_Click(sender As Object, e As EventArgs) Handles editMasinfor.Click
        If main.PROVIDERPOLICIES.checklogin_user_ = True Then
            If PROVIDER_Check.PUPD_ = True Then
                If INFIDTxt.Text.ToString.Length > 0 And INFORMANTTxt.Text.ToString.Length > 0 Then
                    Dim editStat As Integer
                    editStat = MsgBox("ท่านต้องการแก้ไขกลุ่มผู้ให้ข้อมูลดังกล่าวใช่หรือไม่", MsgBoxStyle.OkCancel)

                    If editStat = 1 Then
                        Dim objEditData As New masinfor
                        objEditData.INFID_ = INFIDTxt.Text
                        objEditData.INFORMANT_ = INFORMANTTxt.Text
                        objEditData.STATUS_ = masinforStatusChk.Checked
                        objEditData.editMasinforData()

                        SelectDatagridMASINFOR()

                        INFIDTxt.Text = ""
                        INFORMANTTxt.Text = ""
                        masinforStatusChk.Checked = False
                    End If
                Else
                    MsgBox("โปรดระบุข้อมูลให้ครบถ้วน")
                End If
            Else
                MsgBox(PROVIDER_Check.PUPDMSG_)
            End If
        Else
            TOASTCLASS.gloadToastMSG(Me, main.PROVIDERPOLICIES.LOGINUSERMSG_)
            main.txtUserRequest.Focus()
        End If
    End Sub

    Private Sub importExel_Click(sender As Object, e As EventArgs) Handles importExel.Click
        Dim nextform As New IMPORTEXCEL("masinfor")
        nextform.ShowDialog()
    End Sub

    Private Sub exportExcel_Click(sender As Object, e As EventArgs) Handles exportExcel.Click
        Dim nextform As New IMPORTEXCEL("masinfor")
        nextform.ShowDialog()
    End Sub
End Class